#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

void rand_func(int param[], const int n);

void poly_eval()
{
    int param[10] = {0};
    const int n = 10;
    const int x = (rand()%9);
    cout << "the x is: " << x << endl;
    rand_func(param, n);

    int y = 1, value = param[0];
    for (int ix = 1; ix < 10; ix ++) {
        y *= (x * x);
        value += y * param[ix];
    }
    cout << "The result is: " << value << endl;
}

void rand_func(int param[], const int n)
{
    cout << "The rand data: ";
    for (int ix = 0; ix < n; ix ++) {
         param[ix] = (rand() % 99);
         cout << param[ix] << ' ';
    }
    cout << endl;
}

void horner()
{
    int param[10] = {0};
    const int n = 10;
    const int x = (rand()%9);
    cout << "the x is: " << x << endl;
    rand_func(param, n);

    int value = param[n - 1];
    for (int ix = 1; ix < n; ix ++) {
         value = value * x + param[n - ix - 1];
    }
    cout << "The result is: " << value << endl;
}

template<class Type>
void select_sort(Type &a, int n)
{
    bool sorted = false;
    int indexMax = 0;

    for (int size = n; !sorted && (size > 1); ) {       
        sorted = true;

        for (int i = 1; i < n; i++) {
            if (a[indexMax] < a[i])
                indexMax = i;
            else 
                sorted = false;                    
        }
        
        if (a[indexMax] > a[n - 1]) {
            swap(a[indexMax], a[n - 1]);
        }
        
        for (int ix = 0; ix < n; ix ++)
            cout << a[ix] << ' ';
        cout << endl;
        size -= indexMax;
    }
}

void select()
{
    int param[6] = {53, 41, 82, 99, 67, 90};
    const int n = 6;
   // rand_func(param, n);
    select_sort(param, n);
    for (int ix = 0; ix < n; ix ++)
        cout << param[ix] << ' ';
    cout << endl;
}

int main()
{
    select();
    return 0; 
}